package server

import (
	"context"
	"github.com/go-kratos/kratos/v2/log"
	"github.com/hibiken/asynq"
)

// TaskServer 隊列任務
type TaskServer struct {
	Server *asynq.Server
	Mux    *asynq.ServeMux
}

func NewTaskServer(server *asynq.Server, mux *asynq.ServeMux) *TaskServer {
	return &TaskServer{
		Server: server,
		Mux:    mux,
	}
}

func (s *TaskServer) Start(ctx context.Context) error {
	log.Info("task server start")
	return s.Server.Run(s.Mux)
}

func (s *TaskServer) Stop(ctx context.Context) error {
	log.Info("task server stop")
	s.Server.Shutdown()
	return nil
}
